package org.apple.console;

import org.apple.data.SensorReading;
import org.apple.transmitter.Transmitter;

public class ConsoleTransmiter implements Transmitter {
	
	private HarnessFrame frame;
	
	public ConsoleTransmiter() {
		this.frame = new HarnessFrame();
	}

	public void init() {
		frame.resize(800, 600);
		frame.show();
	}

	public void send(String str) {
		System.out.println("Run: [ConsoleTransmitter -> send()]\t" + str);
		String[] items = str.split(";");
		for (int i = 0; i < items.length; i ++) {
			String[] pair = items[i].split(",");
			int type = Integer.parseInt(pair[0]);
			switch (type) {
			case SensorReading.SPEED:
				frame.receiveData(type, pair[1]);
				break;
			case SensorReading.AIRTEMPRATURE:
				frame.receiveData(type, pair[1]);
				break;
			case SensorReading.SEATEMPRATURE:
				frame.receiveData(type, pair[1]);
				break;
			case 4:
				// location
				frame.receiveData(type, pair[1]);
				break;
			case 5:
				// message id
				break;
			default:
				System.err.println("[Run error!! Console Transimitter]");
			}
			
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		ConsoleTransmiter tran = new ConsoleTransmiter();
		tran.init();
		for (int i = 0; i < 100; i ++) {
			System.out.println("i = " + i);
			Thread.sleep(1000);
			tran.send("1,0.5;2,0.6;3,0.7;4,0.9;5,1;");
		}

	}

}
